<?php
/**
 * 排行统计模型层
 * 
 * @copyright 	Copyright (c) 2011 thinkapk.com All rights reserved.
 * @package 	ThinkAPK_Model
 * @link 		http://www.thinkapk.com/
 * @author 		richie <richbossman@163.com>
 * @version 	$Id: GoodsCountModel.class.php 7285 2011-04-22 09:52:33Z richie $
 * 
 */
class GoodsCountModel extends CommonModel {
	
	//取得排行数据
	function get($cat_id=0, $limit=10){
		$map['g.is_delete'] = 0;
		$map['g.is_on_sale'] = 1;
		if($cat_id){
			$cat = D('Category')->getChiledrenId($cat_id);
			$map['gc.cat_id'] = array('in', $cat);
			unset($cat, $cat_id);
		}
		$map['_string'] = "g.goods_id=gc.goods_id";
		$row = $this->table($this->tablePrefix.'goods_count AS gc,'.$this->tablePrefix.'goods AS g')
			->field('g.goods_id as id, g.goods_name as title, g.short_title, g.goods_icon as icon, g.short_desc as gdesc, g.recommend, gc.down_total as total')
			->order('gc.down_total DESC, g.goods_id DESC')
			->limit($limit)
			->where($map)
			->findAll();
		if($row){
			foreach ($row AS $key=>$app){
				$row[$key]['url'] = U('thinkapk://Android/index', array('id'=>$app['id']));
				$row[$key]['short_title'] = !empty($app['short_title'])?$app['short_title']:$app['title'];
				$row[$key]['icon'] = $this->getIconPath($app['icon']);
				unset($row[$key]['goods_name'], $app);
			}
		}
		unset($limit, $map);
		return $row;
	}
}
?>